import os

from langchain.chains import llm
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import PromptTemplate
from openai import OpenAI

client = OpenAI(
  api_key=os.getenv("OPENAI_API_KEY"),
  base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
)

prompt = PromptTemplate.from_template("请给我的花店起个名")

response = client.completions.create(
  model="deepseek-r1-distill-qwen-1.5b",
  temperature=0.5,
  max_tokens=100,
  prompt=prompt)

print(response.choices[0].text.strip())

# 使用输出解析器自动解析响应
output_parser = StrOutputParser()

# 组合调用
chain = prompt | llm | output_parser
result = chain.invoke({})
print(result)